import java.util.Scanner;
import java.util.*;

public class Test2 {
    public static class Node{
        char value;
        Node left;
        Node right;
    }
    static int i;
    public static void BdisPlay(Node head){
        if (head == null){
            return;
        }
        BdisPlay(head.left);
        System.out.print(head.value + " ");
        BdisPlay(head.right);
    }
    public static Node structure(String str){
        Node node = null;
        if (str.charAt(i) != '#'){
            node = new Node();
            node.value = str.charAt(i);
            i++;
            node.left = structure(str);
            node.right = structure(str);
        }else {
            i++;
        }
        return node;
    }
    public static void main(String[] args) {
        Stack<Iterable> stack = new Stack<>();
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()){
            String str = scanner.nextLine();
            if (str == null || str.charAt(0) == '#') {
                return;
            }
            Node tmp = structure(str);
            BdisPlay(tmp);
            System.out.println();
        }
    }

}
